package com.my.hp_hr.contorller.liuhao_controller;

import com.alibaba.fastjson.JSONObject;
import com.my.hp_hr.entity.liuhao_entity.Leave;
import com.my.hp_hr.util.LeaveDayUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/toAddLeave")
public class ToAddLeaveServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter pw = resp.getWriter();
        Leave leave = new Leave();
        String start_time = req.getParameter("start_time");
        String end_time = req.getParameter("end_time");
        String days="";
        if (start_time!=null&&end_time!=null&&!"".equals(start_time.trim())&&!"".equals(end_time.trim())){
            days = LeaveDayUtil.dateToDays(start_time, end_time);
        }
        leave.setDays(days);
        String leave_String = JSONObject.toJSONString(leave);
        pw.write(leave_String);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
